package com.ye.service.impl;


import com.ye.domain.Comments;
import com.ye.feign.CommentsFeign;
import com.ye.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentsFeign commentsFeign;

    @Override
    public List<Comments> getAllCommentsByMusicId(Integer musicId) {
        return commentsFeign.getAllCommentsByMusicId(musicId);
    }

    @Override
    public List<Comments> getFirsts(Long musicId) {
        return commentsFeign.getFirsts(musicId);
    }

    @Override
    public List<Comments> getChilds(Long commentsId) {
        return commentsFeign.getChilds(commentsId);
    }


//    合并二级菜单，最终返回
    @Override
    public List<Comments> secondLevelMerge(Long musicId){

        List<Comments> firsts = getFirsts(musicId);
        List<Comments> commentsList = firsts.stream().map((item) -> {
            item.setChild(getChilds(item.getCommentId()));
            return item;
        }).collect(Collectors.toList());

        return commentsList;

    }

    @Override
    public void firstComment(Long musicId, String content, Long userId) {
        commentsFeign.firstComment(musicId, content, userId);
    }

    @Override
    public void reply(Long musicId, Long parentId, String content, Long userId) {
        commentsFeign.reply(musicId, parentId, content, userId);
    }
}
